home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Celestin Apprentice 5
/
Apprentice-Release5.iso
/
Source Code
/
Libraries
/
WASTE 1.2
/
WASTE Demo ƒ
/
DialogUtils.c
next >
Wrap
Text File
|
1996-05-19
|
4KB
|
151 lines
/*
WASTE Demo Project:
Dialog Utilities
Copyright © 1993-1996 Marco Piovanelli
All Rights Reserved
C port by John C. Daub
*/
#ifndef __DIALOGS__
#include <Dialogs.h>
#endif
#ifndef __WEDEMOAPP__
#include "WEDemoIntf.h"
#endif
static pascal Boolean MyStandardDialogFilter( DialogRef dialog, EventRecord *event, short *item )
{
GrafPtr savePort;
ModalFilterUPP stdFilter = nil;
Boolean retval = false;
OSErr err;
// set up the port
GetPort( &savePort );
SetGrafPortOfDialog( dialog );
// intercept window events directed to windows behind the dialog
if ( ( event->what == updateEvt ) || ( event->what == activateEvt ) )
{
if ( ((WindowRef) event->message) != GetDialogWindow( dialog ) )
{
DoWindowEvent( event );
}
}
// is the default item a pushbutton?
if ( GetDialogItemType( dialog, GetDialogDefaultItem( dialog ) ) == kButtonDialogItem )
{
// yes, so tell the Dialog Manager to care about its outline
SetDialogDefaultItem( dialog, GetDialogDefaultItem( dialog ));
}
// this is something not in the original WASTE Demo App, but in the work that I've done
// on my own projects, I've found it useful and helpful.
// let's also make sure the cancel button can be handled...now, the cancel button
// should be dialog item #2. So, we get dialog item #2, check if it's a button.
// if it fills these 2 criteria, it's cancel. Even if the default item and the
// cancel item are the same, still let them both be set this way so whatever keyboard
// keys sthe user presses will be handled properly
// pass the number "2" to GetDialogItemType...don't check for the cancel item (cause tho
// cancel is defined as 2, we're not looking for cancel, we're looking for dialog item #2
// this is just more readable code.
// remember, this assumes that your cancel item will be item #2 (or at least the item
// that you want to use for cancelling is #2), and that there are at least 2 items in
// the dialog to begin with!
if ( GetDialogItemType( dialog, kStdCancelItemIndex ) == kButtonDialogItem )
{
SetDialogCancelItem( dialog, kStdCancelItemIndex );
}
// call the standard Dialog Manager filter procedure
if ( ( ( err = GetStdFilterProc( &stdFilter ) ) == noErr ) && ( stdFilter != nil ) )
{
retval = CallModalFilterProc( stdFilter, dialog, event, item );
}
// restore the port
SetPort( savePort );
return retval;
}
ModalFilterUPP GetMyStandardDialogFilter( void )
{
#ifdef __cplusplus
static ModalFilterUPP sFilterUPP = NewModalFilterProc( MyStandardDialogFilter );
#else
static ModalFilterUPP sFilterUPP = nil;
if ( sFilterUPP == nil )
{
sFilterUPP = NewModalFilterProc( MyStandardDialogFilter );
}
#endif
return sFilterUPP;
}
short GetDialogItemType( DialogRef dialog, short item )
{
short itemType;
Handle itemHandle;
Rect itemRect;
GetDialogItem( dialog, item, &itemType, &itemHandle, &itemRect );
return itemType;
}
Handle GetDialogItemHandle( DialogRef dialog, short item )
{
short itemType;
Handle itemHandle;
Rect itemRect;
GetDialogItem( dialog, item, &itemType, &itemHandle, &itemRect );
return itemHandle;
}
void GetDialogItemRect( DialogRef dialog, short item, Rect *itemRect )
{
short itemType;
Handle itemHandle;
GetDialogItem( dialog, item, &itemType, &itemHandle, itemRect );
}
void SetDialogItemProc( DialogRef dialog, short item, UserItemUPP proc )
{
short itemType;
Handle itemHandle;
Rect itemRect;
GetDialogItem( dialog, item, &itemType, &itemHandle, &itemRect );
if ( ( itemType & 0x007F) == userItem )
{
SetDialogItem( dialog, item, itemType, (Handle) proc, &itemRect );
}
}
void FlashButton( DialogRef dialog, short item )
{
ControlRef button;
long finalTicks;
button = (ControlRef) GetDialogItemHandle( dialog, item );
HiliteControl( button, kControlButtonPart );
Delay( 8, &finalTicks );
HiliteControl( button, kControlNoPart );
}